#include <iostream>
#include <string>

#include <coin/proto/symbology.pb.h>
#include <nlohmann/json.hpp>
#include <gflags/gflags.h>

#include "coin2/base/hostname_util.h"
#include "coin2/exchange/base/symbology/product_holder_manager.h"
#include "coin2/exchange/factory/symbology/product.h"

DEFINE_string(mea, "", "Specify market.exchange.api_version.");
DEFINE_string(timestamp, "", "Specify trading date.");
DEFINE_string(native_symbol, "", "");
DEFINE_string(norm_symbol, "", "");
DEFINE_string(root_dir, "~/workspace/coin_product_info/data", "");

int main(int argc, char* argv[]) {
  google::InitGoogleLogging(argv[0]);
  gflags::ParseCommandLineFlags(&argc, &argv, true);

  coin::proto::ProductHolderManagerConfig config;
  config.set_search_policy(coin::proto::ProductHolderManagerConfig::Exact);
  config.set_root_dir(ExpandUser(FLAGS_root_dir));
  coin2::exchange::base::symbology::ProductHolderManager product_holder_manager(config);

  auto mea = MarketExchangeApi::FromString(FLAGS_mea);
  int64_t timestamp = std::stoll(FLAGS_timestamp);
  std::string native_symbol = FLAGS_native_symbol;
  std::string norm_symbol = FLAGS_norm_symbol;

  if (!native_symbol.empty()) {
    auto product = CreateProductFromNativeString(mea, native_symbol, timestamp, false);
    auto* product_holder = product_holder_manager.GetProductHolder(*product, timestamp);
    CHECK(product_holder) << native_symbol;
  }

  if (!norm_symbol.empty()) {
    auto product = CreateProductFromNormString(mea, norm_symbol, timestamp, false);
    auto* product_holder = product_holder_manager.GetProductHolder(*product, timestamp);
    CHECK(product_holder) << norm_symbol;
  }

  return 0;
}
